﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using Model;
namespace DAL
{
    public class ManageDAL
    {
        DBHelper db = new DBHelper();
        public bool Dento(Manage id)
        {
            string sql = $"select ManageID, ManageName, ManagePwd, MangeAddress from [dbo].[Manage] where ManageName='{id.ManageName}' and ManagePwd='{id.ManagePwd}'";
            if (db.GetData(sql).Tables[0].Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
        public List<Manage> ShowManage()
        {
            string sql = $"select ManageID, ManageName, ManagePwd, MangeAddress from [dbo].[Manage]";
            List<Manage> list = null;
            DataTable tb = db.GetData(sql).Tables[0];
            if (tb.Rows.Count > 0)
            {
                //ManageID, ManageName, ManagePwd, MangeAddress
                list = new List<Manage>();
                for (int i = 0; i < tb.Rows.Count; i++)
                {
                    Manage ma = new Manage();
                    ma.ManageID = Convert.ToInt32(tb.Rows[i]["ManageID"]);
                    ma.ManageName = tb.Rows[i]["ManageName"].ToString();
                    ma.ManagePwd = tb.Rows[i]["ManagePwd"].ToString();
                    ma.MangeAddress = tb.Rows[i]["MangeAddress"].ToString();
                    list.Add(ma);
                }
            }
            return list;
        }
        public bool Update(Manage manage, int num)
        {
            string sql = $"update [dbo].[liber] set liberConut=liberConut-'{num}' where liberID='{manage.ManageID}'";
            return db.SetData(sql);
        }
    }
}
